package com.igeek.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.mapper.InsuranceFlowableMapper;
import com.igeek.model.claims.InsuranceFlowable;
import com.igeek.service.IInsuranceFlowableService;
import com.igeek.vo.process.ProcessDto;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-19
 */
@Service
public class InsuranceFlowableServiceImpl extends ServiceImpl<InsuranceFlowableMapper, InsuranceFlowable> implements IInsuranceFlowableService {
   @Autowired
   private InsuranceFlowableMapper insuranceFlowableMapper;
    @Autowired
    RepositoryService repositoryService;
    @Override
    public void addTemplate(ProcessDto processDto) {
        InsuranceFlowable insuranceFlowable = new InsuranceFlowable();
        insuranceFlowable.setName(processDto.getName());
        insuranceFlowable.setType(processDto.getType());
        insuranceFlowable.setPersons(processDto.getId1()+","+processDto.getId2());
        insuranceFlowable.setCreatedTime(processDto.getCreatedTime());
        String name = processDto.getName();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("process/" + name + ".bpmn20.xml")
                //部署名
                .name("部署名称:" + name)
                .key("key-" + name)
                .deploy();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
        insuranceFlowable.setProcDefId(processDefinition.getId());
        this.baseMapper.insert(insuranceFlowable);
    }

    @Override
    public String[] getPerson(Integer id) {
        InsuranceFlowable insuranceFlowable=insuranceFlowableMapper.selectById(id);
        String persons = insuranceFlowable.getPersons();
        String[] person = persons.split(",");
        return person;

    }
}
